package com.thenie.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description
 * @Author thenie
 * @Data 2022/5/6 15:58
 */
@Configuration
public class RabbitMQConfig {
    //队列id
    private static final String QUEUE = "seckillQueue";
    //交换机id
    private static final String EXCHANGE = "seckillExchange";

    /**
     * 生成一个队列 QUEUE
     * @return
     */
    @Bean
    public Queue queue(){
        return new Queue(QUEUE);
    }

    /**
     * 生成一个交换机 EXCHANGE
     * @return
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(EXCHANGE);
    }

    /**
     *  将队列和交换机进行绑定，用来接收 routingKey 为 seckill.# 的消息
     * @return
     */
    @Bean
    public Binding binding01(){
        return BindingBuilder.bind(queue()).to(topicExchange()).with("seckill.#");
    }
}